package org.osomit.sacct.provider.impl.spring;

import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.AfterClass;
import static org.junit.Assert.assertNotNull;
import org.springframework.core.io.Resource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import test.iface.PasswordReader;

/**
 * Manual Test. Need to run the sacct-server to make the test pass
 *
 * @author Jian Fang (John.Jian.Fang@gmail.com)
 *
 * Date: Jul 5, 2009
 * 
 */
public class AccountProvider_MT {
    private static PasswordReader reader;
    private static XmlBeanFactory factory;

    protected static String getSpringWiringFilename(Class testClass) {
    	return testClass.getResource(testClass.getSimpleName() + ".xml").toExternalForm().substring(5);
    }

    @BeforeClass
    public static void loadSpringBeans(){
        String fileName =  getSpringWiringFilename(AccountProvider_MT.class);
        Resource xmlResource = new FileSystemResource(fileName);
//        Resource xmlResource = new ClassPathResource(fileName);
        factory = new XmlBeanFactory(xmlResource);
    }

   @Test
    public void testShowPasswordsWithActiveProvider(){
        reader = (PasswordReader)factory.getBean("passwordReader1");
        assertNotNull(reader);
        System.out.println(reader.showPassword());
    }

    @Test
    public void testShowPasswordsWithInactiveProvider(){
        reader = (PasswordReader)factory.getBean("passwordReader2");
        assertNotNull(reader);
        System.out.println(reader.showPassword());
    }

    @AfterClass
    public static void destroy(){
        if(factory != null){
            factory.destroySingletons();
            factory = null;
        }
    }
}
